/*
 * @Description: 幸运数字
 * @Author: zzj
 * @Date: 2021-09-09 14:26:58
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-09 16:28:33
 */

/*
封装一个函数，判断n是否是幸运数字
幸运数：length为偶数，并且前一半的和等于后一半的和。例如：isLucky(1230)=true
 */

const readline = require("readline-sync");
var num = readline.question("请输入数字：");
function isLucky(num){
    var str = num.toString();
    var s1 = 0 , s2 = 0;
    if ((str.length)%2==0){
        for(k in str){
            if(k<(str.length)/2){
                s1 += Number(str[k])
            }else{
                s2 += Number(str[k])
            }
        }
        if(s1 == s2){
            console.log(num+"为幸运数字");
        }else{
            console.log(num+"不是幸运数字");
        }
    }else{
        console.log("输入数字必须为偶数")
    }
}
isLucky(num);
